#include "stdafx.h"
MFile::MFile()
{
	file=new TFile;
}
MFile::~MFile()
{
	delete file;
}
MFile::MFile(char *filename)
{
	file=new TFile(filename,P_ADD|P_UPDATE|P_BINARY);
}
void MFile::Open(char *filename)
{
	if (file!=NULL)
		delete file;
	file=new TFile(filename,P_ADD|P_UPDATE|P_BINARY);
}
FILE * MFile::GetFile()
{
	return file->Get();
}
uint MFile::GetID()
{
	uint id;
	file->Seek(sizeof(uint),S_CURRENT);
	file->Read(&id,sizeof(uint),1);
	file->Seek(-2*sizeof(uint),S_CURRENT);
	return id;
}
void MFile::GetURL(char *buf)
{
	uint BlockSz;
	file->Read(&BlockSz,sizeof(BlockSz),1);
	file->Seek(sizeof(BlockSz),S_CURRENT);
	file->Read(buf,sizeof(char),BlockSz-2*sizeof(BlockSz));
	file->Seek(-BlockSz,S_CURRENT);
}
void MFile::GoToNextBlock()
{
	uint BlockSz;
	file->Read(&BlockSz,sizeof(BlockSz),1);
	file->Seek(BlockSz-sizeof(BlockSz),S_CURRENT);
}
void MFile::Write(uint ID, char *url)
{
	uint BlockSz=sizeof(ID)+sizeof(uint)+strlen(url);
	file->Write(&BlockSz,sizeof(BlockSz),1);
	file->Write(&ID,sizeof(ID),1);
	file->Write(url,sizeof(url[0]),strlen(url));
}